#include "MatrixKey.h"
#include "Delay.h"

uchar MatrixKey()
{
	uchar keyValue = -1;
	char a = 0;
	P1 = 0x0F;
	if(P1 != 0x0F) {
		Delay(15);
		P1 = 0x0F;	
		switch(P1) {
			case(0x07):	keyValue = 0; break;
			case(0x0B):	keyValue = 1; break;
			case(0x0D): keyValue = 2; break;
			case(0x0E):	keyValue = 3; break;
		}

		P1 = 0xF0;
		switch(P1) {
			case(0x70):	keyValue = keyValue; break;
			case(0xB0):	keyValue = keyValue + 4; break;
			case(0xD0): keyValue = keyValue + 8; break;
			case(0xE0):	keyValue = keyValue + 12; break;
		}
		while(P1 != 0xF0);
		Delay(15);
	}
	return keyValue;
}